<?php

if(isset($_GET['sensorId'])){

   $sensorId=$_GET['sensorId'];  
   if(!$pg_conn){
      include "dbRcoos.php";
   }
   
 
    $stmt=pg_query ($pg_conn, "select m_type_id from sensor where row_id=$sensorId");
    while($row1=pg_fetch_row($stmt)){
        $mtype=$row1[0];
    }
    
    if($mtype){
      $stmt=pg_query ($pg_conn, "select uom_type.display,uom_type.standard_name,uom_type.alt_name from uom_type
                      join m_scalar_type on m_scalar_type.uom_type_id=uom_type.row_id
                      join m_type on m_type.m_scalar_type_id=m_scalar_type.row_id
                      where m_type.row_id=$mtype");
      while($row1=pg_fetch_row($stmt)){
          $unit=$row1[0];
          $unitvalue=$row1[1];
          $alt=$row1[2];
      }    
    }

  
     if($unit){
         if($alt){   $a=explode(",",$alt);}
  
         if($alt){
            
            for($i=0;$i<count($a);$i++){
               $temp=$a[$i]; 
               if($a[$i]=='fahrenheit'){$a[$i]="deg F";}
               echo "obj.options[obj.options.length] = new Option('$a[$i]','$temp');\n";
               //print "</option>";
            }
         }
         //print "<option value=$unitvalue>$unit</option>";
         echo "obj.options[obj.options.length] = new Option('$unit','$unitvalue',1,1);\n";
         //print "</select>";
     }

   
}

?>
